//
//  ZDPopoverViewController.m
//  OCSinaWeiBo
//
//  Created by Apple on 15/11/10.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "ZDPopoverViewController.h"
#import <Masonry/Masonry.h>

@interface ZDPopoverViewController () <UITableViewDataSource>

@property (nonatomic, strong) UIImageView *bkgView;

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSArray *datas;

@end

@implementation ZDPopoverViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self prepareUI];
    
    self.datas = @[@"新浪微博", @"腾讯微博", @"我的微博", @"别人的微博"];
}


- (void)prepareUI
{
    [self.view addSubview:self.bkgView];
    [self.view addSubview:self.tableView];
    
    
    [_bkgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.bottom.right.mas_equalTo(self.view);
    }];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.view).offset(20);
        make.left.mas_equalTo(self.view).offset(15);
        make.bottom.right.mas_equalTo(self.view).offset(-15);
    }];
    
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
}



#pragma mark - 数据源
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.textLabel.text = self.datas[indexPath.row];
    
    return cell;
}


#pragma mark 懒加载
- (UIImageView *)bkgView
{
    if (!_bkgView)
    {
        _bkgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"popover_background"]];
    }
    
    return _bkgView;
}

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc] init];
        
        _tableView.dataSource = self;
    }
    
    return _tableView;
}

@end
